package com.huawei.appmarket.service.appdetail.view.card;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.gamereserve.bean.OrderAppCardBean;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appdetail.view.widget.DetailDownloadButton;
import com.huawei.appmarket.service.appdetail.view.widget.DetailDownloadButton.d;
import com.huawei.appmarket.service.appdetail.view.widget.DetailShareButton;
import com.huawei.fastengine.fastview.FastSDKEngine;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.bch.a;
import o.bci;
import o.bcm;
import o.bcn;
import o.ccz;
import o.cdb;
import o.cdg;
import o.cke;
import o.cki;
import o.cwv;
import o.dgh;
import o.dgm;
import o.dke;
import o.Logger;
import o.dof;
import o.doo;
import o.ContentManager;
import o.drd;
import o.drl;
import o.drn;
import o.drq;
import o.dvq;
import o.dwk;
import o.ept;
import o.epv;
import o.erz;
import o.evk;
import o.evx;
import o.ewm.c;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.fho;

public class DetailDownloadCard extends drl implements drn, d {
    private View ʻ;
    private String ʻॱ;
    private View ʼ;
    private DetailShareButton ʽ;
    private boolean ˊॱ;
    private DetailDownloadButton ˋॱ;
    private DetailHiddenBean ˏॱ;
    private View ͺ;
    private View ॱˊ;
    private String ॱˋ;
    private dke ॱˎ;
    private View ॱॱ;

    class e extends evx {
        final /* synthetic */ DetailDownloadCard ˏ;

        private e(DetailDownloadCard detailDownloadCard) {
            this.ˏ = detailDownloadCard;
        }

        public void ˋ(View view) {
            if (view == this.ˏ.ʼ) {
                if (this.ˏ.ʼ()) {
                    this.ˏ.ʽ.ˊॱ();
                } else {
                    this.ˏ.ʽ.ͺ();
                }
            } else if (view == this.ˏ.ॱॱ) {
                drq.ॱ(this.ˏ, this.ˏ.ˏॱ, 7);
                new dwk().ॱ(this.ˏ.ˏॱ.ॱـ());
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                linkedHashMap.put(RpkInfo.APPID, this.ˏ.ˏॱ.ͺˏ());
                linkedHashMap.put("type", String.valueOf(7));
                linkedHashMap.put("service_type", String.valueOf(dgm.ˎ((Activity) view.getContext())));
                linkedHashMap.put("detailid", this.ˏ.ˏॱ.ॱॱ());
                dgh.ˋ("card_installbtn_click", linkedHashMap);
                this.ˏ.ˎ(this.ˏ.ˋॱ.ॱ());
            } else if (view == this.ˏ.ॱˊ) {
                this.ˏ.ˊ(view);
            }
        }
    }

    public DetailDownloadCard() {
        this.ˊॱ = false;
        this.ॱˎ = null;
        this.ॱ = 305;
    }

    @SuppressLint({"InflateParams"})
    public View ˊ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ˊ = layoutInflater.inflate(h.ˍ, null);
        azb.ˏ(this.ˊ);
        this.ˊ.setBackgroundColor(this.ˊ.getContext().getResources().getColor(c.ॱˎ));
        this.ʼ = this.ˊ.findViewById(j.ˏﹳ);
        FrameLayout frameLayout = (FrameLayout) this.ˊ.findViewById(j.ⁱॱ);
        if (!epv.ʼ(frameLayout.getContext())) {
            frameLayout.getLayoutParams().width = azb.ॱ(ContentManager.getInstant().getContext()) / 2;
        }
        this.ʽ = (DetailShareButton) this.ˊ.findViewById(j.ˏꜟ);
        this.ॱॱ = this.ˊ.findViewById(j.ˏـ);
        this.ʻ = this.ˊ.findViewById(j.ˑˊ);
        this.ॱˊ = this.ˊ.findViewById(j.ˑˋ);
        this.ͺ = this.ˊ.findViewById(j.ˏꓸ);
        this.ˋॱ = (DetailDownloadButton) this.ˊ.findViewById(j.ˎﹳ);
        OnClickListener eVar = new e();
        this.ˊ.setOnClickListener(eVar);
        this.ॱॱ.setOnClickListener(eVar);
        this.ॱˊ.setOnClickListener(eVar);
        this.ʼ.setOnClickListener(eVar);
        this.ˋॱ.setDownloadEventWatcher(this);
        if (this.ॱˎ != null) {
            this.ˋॱ.setButtonStyle(this.ॱˎ);
        }
        return this.ˊ;
    }

    public void ॱ() {
        super.ॱ();
        if (this.ˋॱ != null) {
            this.ˋॱ.ॱ();
        }
    }

    public void ˊ(dke o_dke) {
        this.ॱˎ = o_dke;
    }

    public void ˏ(String str) {
        this.ʻॱ = str;
    }

    public void ˎ(String str) {
        this.ॱˋ = str;
    }

    public boolean ˊ(List<JsonBean> list) {
        int i = 0;
        if (list == null || list.size() <= 0) {
            return false;
        }
        this.ˏॱ = (DetailHiddenBean) list.get(0);
        if (this.ˏॱ == null) {
            return false;
        }
        if (!TextUtils.isEmpty(this.ॱˋ)) {
            this.ˏॱ.ˏॱ(ept.ॱ(this.ˏॱ.ʾ(), this.ॱˋ));
        }
        if (this.ˏॱ.ॱ() == 1) {
            this.ʼ.setVisibility(8);
            this.ʻ.setVisibility(0);
            this.ॱॱ.setVisibility(8);
            this.ॱˊ.setVisibility(8);
            this.ͺ.setVisibility(0);
        } else if (this.ˏॱ.ͺ() == 15) {
            this.ʼ.setVisibility(8);
            this.ʻ.setVisibility(0);
            this.ॱॱ.setVisibility(8);
            this.ॱˊ.setVisibility(8);
            this.ͺ.setVisibility(0);
        } else {
            ᐝ();
            if (UserSession.getInstance().isLoginSuccessful() && this.ˏॱ.ㆍ() == null && !TextUtils.isEmpty(this.ˏॱ.ͺˏ())) {
                i = 1;
            }
            if (i != 0) {
                ʽ();
            }
        }
        if (this.ˏॱ.ͺ() == 3) {
            RpkInfo rpkInfo = new RpkInfo();
            rpkInfo.setPackageName(this.ˏॱ.ॱـ());
            Logger.ˎ("DetailDownloadCard", "show rpk detail:" + this.ˏॱ.ॱـ());
            FastSDKEngine.onShowRpkDetail(rpkInfo, ContentManager.getInstant().getContext());
        }
        if (!ʼ()) {
            if (!TextUtils.isEmpty(this.ʻॱ)) {
                this.ˏॱ.ˊˋ(this.ˏॱ.u_() + ";" + this.ʻॱ);
            }
            this.ˋॱ.setParam(this.ˏॱ);
        }
        cke ॱ = this.ˋॱ.ॱ();
        if (this.ˏॱ.ॱـ() != null) {
            drd.ˏ(this.ˏॱ.ॱـ(), this.ˏॱ.ˎˎ());
        }
        ˎ(ॱ);
        return true;
    }

    private void ᐝ() {
        if (this.ˏॱ.ͺ() == 3) {
            this.ʽ.setShareContent(this.ˏॱ.ꞌ());
        }
        this.ʽ.setTitle(this.ˏॱ.v_());
        this.ʽ.setIcon(this.ˏॱ.ॱˌ());
        this.ʽ.setShareUrl(this.ˏॱ.ᶥ());
        this.ʽ.setAppId(this.ˏॱ.ͺˏ());
        this.ʽ.setVersion(this.ˏॱ.ˎˎ());
        this.ʽ.setPackageName(this.ˏॱ.ॱـ());
        this.ʽ.setShareType(this.ˏॱ.ʹ());
        if (ʼ()) {
            String ˋ = cwv.ॱ().ˋ();
            this.ʽ.setShareContent(String.format(Locale.ENGLISH, ContentManager.getInstant().getContext().getResources().getString(n.ˉʻ), new Object[]{this.ˏॱ.v_(), ˋ}));
        }
        if (this.ˏॱ.ͺ() == 1) {
            this.ʽ.setH5App(true);
        }
        this.ʽ.setCtype(this.ˏॱ.ͺ());
        this.ʽ.setNavigationColor(ॱˊ());
    }

    public void ॱ(cki o_cki) {
        if (this.ˋॱ != null) {
            this.ˋॱ.setDownloadListener(o_cki);
        }
    }

    public boolean ʼ() {
        return this.ˊॱ;
    }

    public void ˏ(boolean z) {
        this.ˊॱ = z;
    }

    public void ˎ(OrderAppCardBean orderAppCardBean) {
        this.ˋॱ.setParam(orderAppCardBean);
        this.ˋॱ.ॱ();
    }

    public drn ॱॱ() {
        return this;
    }

    private void ˎ(cke o_cke) {
        switch (o_cke) {
            case WAIT_DOWNLOAD_APP:
            case PAUSE_DOWNLOAD_APP:
            case RESUME_DONWLOAD_APP:
            case RESERVE_DOWNLOAD_APP:
                this.ॱॱ.setVisibility(0);
                this.ʻ.setVisibility(8);
                this.ʼ.setVisibility(8);
                return;
            default:
                this.ॱॱ.setVisibility(8);
                if (this.ˏॱ.ॱ() == 1 || this.ˏॱ.ͺ() == 15) {
                    this.ʼ.setVisibility(8);
                    this.ʻ.setVisibility(0);
                    return;
                }
                this.ʼ.setVisibility(0);
                this.ʻ.setVisibility(8);
                return;
        }
    }

    private void ˊ(View view) {
        drq.ॱ(this, this.ˏॱ, 5);
        if (this.ˏॱ.ͺ() == 1 || this.ˏॱ.ͺ() == 3 || (!dof.ॱ(this.ˏॱ.ॱـ()) && erz.ˏ(ˋ().ॱˋ(), this.ˏॱ.ॱـ()))) {
            ͺ();
        } else {
            evk.ˏ(ContentManager.getInstant().getContext(), n.ᶥॱ, 0).ˋ();
        }
    }

    public void ʻ() {
        drq.ॱ(this, this.ˏॱ, 6);
    }

    private void ʽ() {
        Logger.ˎ("DownloadCard", "getCommentInfo, appid:" + this.ˏॱ.ͺˏ());
        int ॱ = ccz.ॱ();
        if (this.ʽ.getContext() instanceof Activity) {
            ॱ = dgm.ˎ((Activity) this.ʽ.getContext());
        }
        String str = null;
        if (this.ˏॱ.ॱـ() != null) {
            PackageInfo ᐝ = ((cdg) cdb.ॱ(cdg.class)).ᐝ(this.ˏॱ.ॱـ());
            if (!(ᐝ == null || ᐝ.versionName == null)) {
                str = ᐝ.versionName;
            }
        }
        ((bcm) fho.ˏ().ˋ("AppComment").ॱ(bcm.class)).ॱ(this.ˏॱ.ͺˏ(), str, 1, ॱ, new bcn(this) {
            final /* synthetic */ DetailDownloadCard ˊ;

            {
                this.ˊ = r1;
            }

            public void ˊ(String str, String str2, String str3) {
                this.ˊ.ˏॱ.ˈ(UserSession.getInstance().getUserId());
                this.ˊ.ˏॱ.ˑ(str3);
                this.ˊ.ˏॱ.ͺॱ(str);
                this.ˊ.ˏॱ.ʼॱ(str2);
            }
        });
    }

    private void ͺ() {
        if (doo.ˊ(ContentManager.getInstant().getContext())) {
            try {
                ((bci) fho.ˏ().ˋ("AppComment").ॱ(bci.class)).ॱ(this.ˎ.ॱˋ(), new a().ˋ(this.ˏॱ.ͺˏ()).ˏ(this.ˏॱ.v_()).ˎ(this.ˏॱ.ॱˌ()).ॱ(this.ˏॱ.ॱـ()).ˊ(this.ˏॱ.ˎˎ()).ʼ(this.ˏॱ.ㆍ()).ʻ(this.ˏॱ.ꓸ()).ॱॱ(this.ˏॱ.ꜟ()).ˎ(ॱˊ()).ˋ());
                return;
            } catch (Throwable e) {
                Logger.ˋ("DetailDownloadCard", "showCommentDialog error", e);
                return;
            }
        }
        evk.ˏ(ContentManager.getInstant().getContext(), n.ʹˊ, 0).ˋ();
    }

    private int ॱˊ() {
        if (this.ˎ == null || this.ˎ.ॱˋ() == null || this.ˎ.ॱˋ().getWindow() == null) {
            return -1;
        }
        return this.ˎ.ॱˋ().getWindow().getNavigationBarColor();
    }

    public void ˏ(Context context, SafeIntent safeIntent) {
        String action = safeIntent.getAction();
        if (dvq.ˊ().equals(action)) {
            ˎ(this.ˋॱ.ॱ());
        } else if ("com.huawei.appmarket.service.broadcast.CommentAdded".equals(action)) {
            Object stringExtra = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID");
            Object stringExtra2 = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_RATING");
            Object stringExtra3 = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_CONTENT");
            if (!TextUtils.isEmpty(stringExtra) && !TextUtils.isEmpty(stringExtra2)) {
                this.ˏॱ.ʼॱ(stringExtra);
                this.ˏॱ.ˑ(stringExtra2);
                if (!TextUtils.isEmpty(stringExtra3)) {
                    this.ˏॱ.ͺॱ(stringExtra3);
                }
            }
        }
    }

    public void ˎ(boolean z) {
        this.ˋॱ.setIsImmersion(z);
        this.ˋॱ.ॱ();
    }
}
